From 9fb3a7566e5a64f3d2f49b6f93a9bb2a046d64f1 Mon Sep 17 00:00:00 2001 From: Factiven Date: Wed, 19 Apr 2023 20:31:08 +0700 Subject: Added Next Airing Date --- pages/anime/[...id].js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'pages/anime/[...id].js') diff --git a/pages/anime/[...id].js b/pages/anime/[...id].js index e2665ea..a437464 100644 --- a/pages/anime/[...id].js +++ b/pages/anime/[...id].js @@ -23,11 +23,13 @@ export default function Himitsu({ progress, status, lastPlayed, + nextAir, }) { const [showText, setShowtext] = useState(false); const [load, setLoad] = useState(true); const [Lang, setLang] = useState(true); const [showAll, setShowAll] = useState(false); + const [time, setTime] = useState(0); const episode = episodeList; const epi1 = episode1; @@ -42,7 +44,13 @@ export default function Himitsu({ setLang(false); } + // console.log(time); + useEffect(() => { + if (nextAir) { + setTime(convertSecondsToTime(nextAir.timeUntilAiring)); + } + function getBrightness(color) { const rgb = color.match(/\d+/g); return (299 * rgb[0] + 587 * rgb[1] + 114 * rgb[2]) / 1000; @@ -139,6 +147,13 @@ export default function Himitsu({

Status:

{info.status}

+ + {/* {nextAir && ( +
+

Ep {nextAir.episode}:

+

{time}

+
+ )} */}
{epi1 && epi1[0] ? ( @@ -222,6 +237,14 @@ export default function Himitsu({ > Sub | {subIndo === null ? "EN" : "EN/ID"}
+ {nextAir && ( +
+ Ep {nextAir.episode}: {time} +
+ )}
item?.media.id === parseInt(info.id)); if (gut) { + nextAir = gut.media.nextAiringEpisode; progress = gut?.progress; if (gut.status === "CURRENT") { status = "Watching"; @@ -690,6 +719,29 @@ export async function getServerSideProps(context) { progress: progress || null, status: status, lastPlayed: lastPlayed || null, + nextAir: nextAir || null, }, }; } + +function convertSecondsToTime(sec) { + let days = Math.floor(sec / (3600 * 24)); + let hours = Math.floor((sec % (3600 * 24)) / 3600); + let minutes = Math.floor((sec % 3600) / 60); + + let time = ""; + + if (days > 0) { + time += `${days}d `; + } + + if (hours > 0) { + time += `${hours}h `; + } + + if (minutes > 0) { + time += `${minutes}m `; + } + + return time.trim(); +} -- cgit v1.2.3